﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Xml.Serialization;
using System.Configuration;

namespace INNOVACALL.Framework.Common.Tools
{
	public static class FileManagerTools
	{
		/// <summary>
		/// Retourne une valeur de config
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		//public static string GetConfigValue(string key)
		//{
		//    return ConfigurationManager.AppSettings.Get(key);
		//}

		/// <summary>
		/// 
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="element"></param>
		/// <param name="fileName"></param>
		/// <returns></returns>
		//public static string SerializeToFile<T>(T element, string fileName)
		//{
		//    // Construct an instance of the XmlSerializer with the type
		//    // of object that is being deserialized.
		//    XmlSerializer mySerializer = new XmlSerializer(typeof(T));
		//    // Call the Deserialize method and cast to the object type.

		//    FileStream sw = new FileStream(fileName, FileMode.OpenOrCreate);
		//    mySerializer.Serialize(sw, element);
		//    sw.Close();
		//    return sw.ToString();
		//}

		//public static string SerializeToFile<T>(T element, string fileName, XmlRootAttribute xmlRoot)
		//{
		//    // Construct an instance of the XmlSerializer with the type
		//    // of object that is being deserialized.
		//    XmlSerializer mySerializer = new XmlSerializer(typeof(T), xmlRoot);
		//    // Call the Deserialize method and cast to the object type.

		//    FileStream sw = new FileStream(fileName, FileMode.OpenOrCreate);
		//    mySerializer.Serialize(sw, element);
		//    sw.Close();
		//    return sw.ToString();
		//}

		/// <summary>
		/// Renvoyer le contenu d'un fichier passé en paramètre sous la forme d'une chaine de caractère
		/// </summary>
		/// <param name="fileName">Chemin complet du fichier</param>
		/// <returns>Contenu du fichier</returns>
		//public static string ReadContentFile(this string fileName)
		//{
		//    try
		//    {
		//        using (TextReader tr = new StreamReader(fileName))
		//        {
		//            return tr.ReadToEnd();
		//        }
		//    }
		//    catch
		//    {
		//        return string.Empty;
		//    }
		//}


		/// <summary>
		/// Récupère le contenu d'une requête GET
		/// </summary>
		/// <param name="uriString">adresse</param>
		/// <returns></returns>
		//public static string ReadHttpContent(string uriString)
		//{
		//    try
		//    {
		//        HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(uriString);
		//        hwr.UserAgent = "WFO SeoService";
		//        WebResponse wr = hwr.GetResponse();
		//        Stream st = wr.GetResponseStream();
		//        StreamReader sr = new StreamReader(st);
		//        string strRet = sr.ReadToEnd();
		//        sr.Close();
		//        wr.Close();

		//        return strRet;

		//        //WebClient wc = new WebClient();
		//        //wc.Encoding = System.Text.Encoding.UTF8;
		//        //return wc.DownloadString(uriString);
		//    }
		//    catch (Exception)
		//    {
		//        return "";
		//    }
		//}
	}
}
